<template>
	<view class="video-play">
		<image :src="videodetail.img"></image>
		<view class="header">
			<view @click="contralMuted()" :class="ismuted? 'iconfont icon-shengyin-guan':'iconfont icon-shengyin-kai' "></view>
			<view class="iconfont icon-hanhan-01-01 share">
				<button type="default" open-type="share" class="share-btn"></button>
			</view>
		</view>
		<view class="content">
			<video :muted="ismuted" show-center-play-btn objectFit="fill" :src="videodetail.video"></video>
		</view>
		<view class="save">
			<view class="btn" @click="saveVideo()">下载高清</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				videodetail:{},
				ismuted:false
			}
		},
		onLoad(options) {
			let videodetail = decodeURIComponent(options.item)
			this.videodetail = JSON.parse(videodetail);
			console.log(this.videodetail)
		},
		methods:{
			// 声音控制
			contralMuted(){
				this.ismuted=!this.ismuted
			},
			// 下载视频
			async saveVideo(){
				uni.showLoading({
					title:"下载中"
				})
				// 1：将视频先存入小程序缓存，（uni.downloadFile 将下载对象存入小程序缓存）
				const res1 = await uni.downloadFile({url:this.videodetail.video})
				console.log(res1)
				var tempFilePath=res1[1].tempFilePath
				// 2:将视频下载到本地
				const res2 = await uni.saveVideoToPhotosAlbum({filePath:tempFilePath})
				uni.hideLoading()
				uni.showToast({
					title:"下载成功",
					icon:"success"
				})
			}
		}
	}
</script>

<style lang="scss">
	.video-play{
		position: relative;
		image{
			width: 100vw;
			height: 100vh;
			position: absolute;
			left: 0;
			z-index: -1;
			// css3滤镜
			filter: blur(10px);
		}
	}
	.header{
		display: flex;
		justify-content: flex-end;
		padding: 20rpx;
		.iconfont{
			color: #fff;
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			background-color: rgba(0,0,0,0.5);
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0 10rpx;
			font-size: 40rpx;
		}
	}
	.content{
		display: flex;
		justify-content: center;
		align-items: center;
		video{
			width: 400rpx;
			height: 600rpx;
		}
	}
	.save{
		display: flex;
		justify-content: center;
		margin: 20rpx 0;
		.btn{
			width: 360rpx;
			line-height: 70rpx;
			background-color: rgba(0,0,0,0.5);
			border-radius: 50rpx;
			color: #fff;
			text-align: center;
			border: 3rpx solid #fff;
		}
	}
	.share{
		position: relative;
		.share-btn{
			position: absolute;
			width: 100%;
			height: 100%;
			opacity: 0;
			left: 0;
			bottom: 0;
		}
	}
</style>
